﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using InversPong.Model;
using System.Reflection;
using System.ComponentModel;

namespace InversPong.Model
{
    public class PowerUp : MovableObject
    {
        public static readonly int[] defaultPowerUpSize = new int[2] { 40,40 };

        /// <summary>
        /// The timer of the object.
        /// </summary>
        public TimeSpan Timer { get; set; }

        /// <summary>
        /// The initial timer of the object.
        /// </summary>
        public TimeSpan MaxTimer { get; protected set; }

        /// <summary>
        /// The relative progression of the timer against its maximum, given between 0 and 1.
        /// </summary>
        public float Progression { get { return (float)Math.Max(0.0, Math.Min(1.0, Timer.TotalSeconds / MaxTimer.TotalSeconds)); } }

        public enum Types
        {
            Invulnerability,
            Inverse,
            Size_Dim,
            Viagra,
            Moteur,
            Escargot
        }

        public Types Type { get; private set; }

        public PowerUp(Vector2 position, Vector2 velocity, Types type, TimeSpan timer)
            : base(position, velocity, type.ToString().ToLower(), PowerUp.defaultPowerUpSize[0], PowerUp.defaultPowerUpSize[1])
        {
            Type = type;
            Timer = timer;
            MaxTimer = timer;
        }

        
        public static Types GetRandomType(double roll)
        {
            return (Types)(int)(roll * 6);
        }

        public static Types GetRandomType()
        {
            Random r = new Random();

            return PowerUp.GetRandomType(r.NextDouble());
        }

        public void Catched(TimeSpan timer)
        {
            Position = Vector2.Zero;
            Velocity = Vector2.Zero;
            Timer = timer;
            MaxTimer = timer;
        }
        
    }
}
